<?php

require_once(DIR_LIB."VsCore".DIR_SEP."vssession.php");


class VsMessageStack {
	private static $_Instance = NULL;

	private $_messages = array();
	private $_newMessages = array();

	static function Instance() {
		if(!self::$_Instance)
			self::$_Instance = new VsMessageStack();

		return self::$_Instance;
	}
	//====================================================================

	private function __construct() {
		$session = VsSession::Instance();

		if($session->isArray('VsMessageStack')) {
			$this->_messages = $session->value('VsMessageStack');
			$session->remove('VsMessageStack');
		}
	}
	//===================================================================

	function __destruct() {
		if(empty($this->_newMessages))
			return;

		$session = VsSession::Instance();
		$session->assign('VsMessageStack', $this->_newMessages);
	}
	//===================================================================

	function messages($className) {
		if(@is_array($this->_messages[$className]))
			return $this->_messages[$className];
		else
			return array();
	}
	//===================================================================

	function add($className, $messageName, $messageContent) {
		$this->_newMessages[$className][] = array('name'=>$messageName, 'content'=>$messageContent);
	}
	//=====================================================================

	function remove($className) {

	}
	//=====================================================================

	private function removeAll() {

	}
	//=====================================================================
}

?>
